﻿using BLL;
using Model;
using System;
using System.Data;
using System.Text;

namespace Thksoft.MainAspx
{
    /// <summary>
    /// 加载模块 页面 @ID：模块ID
    /// </summary>
    public partial class MenuControl : System.Web.UI.Page
    {
        #region 定义区

        private Sys_ModuleBLL smb = new Sys_ModuleBLL();

        #endregion 定义区

        public Sys_User lognUser;

        #region 页面加载

        protected void Page_Load(object sender, EventArgs e)
        {
            lognUser = (Sys_User)Session["SysUserInfo"];
            if (!IsPostBack)
            {
                var script = new StringBuilder();
                script.AppendLine("<script>");
                string _keyid = Request.QueryString["ID"];

                #region 加载模块信息

                if (!string.IsNullOrEmpty(_keyid))
                {
                    //根据模块ID获得该模块信息

                    switch (_keyid)
                    {
                        case "usinfo":
                            script.AppendLine("top.Class_ItemCard_Oprn.Run_ItemCard('UserInfo','个人信息设置','ViewSystemUserInfo.aspx','0');");
                            break;

                        case "sysinfo":
                            script.AppendLine("top.Class_ItemCard_Oprn.Run_ItemCard('UserInfo','个人信息设置','ViewSystemUserInfo.aspx','0');");
                            break;

                        case "fastinfo":
                            script.AppendLine("top.Class_ItemCard_Oprn.Run_ItemCard('FastInfo','快捷方式设置','ViewSystemFastInfo.aspx','0');");
                            break;

                        case "online":
                            script.AppendLine("top.Class_ItemCard_Oprn.Run_ItemCard('online','在线服务','SystemFastInfo.aspx','0');");
                            break;

                        case "help":
                            script.AppendLine("top.Class_ItemCard_Oprn.Run_ItemCard('helpinfo','使用帮助','SystemFastInfo.aspx','0');");
                            break;

                        default:
                            {
                                try
                                {
                                    DataTable dt;
                                    Sys_Module model = smb.GetInfoById(_keyid);
                                    if (lognUser.USER_ID == 1)
                                    {
                                        //
                                        //script.AppendLine("top.Class_ItemCard_OprnNew.Run_ItemCard('" + _keyid + "','" + model.MODULE_NAME + "','" + "/" + model.MODULE_PATH + "?model_id=" + _keyid + "','0');");
                                        script.AppendLine("top.ICard.Open('" + "/" + model.MODULE_PATH + "','" + model.MODULE_NAME + "');");
                                    }
                                    else
                                    {
                                        Sys_UserBLL suse = new Sys_UserBLL();
                                        dt = suse.GetRoleInfoById(lognUser.USER_ROLEID, _keyid);
                                        if (dt.Rows.Count == 1)
                                        {
                                            script.AppendLine("top.Class_ItemCard_OprnNew.Run_ItemCard('" + _keyid + "','" + model.MODULE_NAME + "','" + "/" + model.MODULE_PATH + "?model_id=" + _keyid + "','0');");
                                        }
                                        else
                                        {
                                            script.AppendLine("alert(\"【温馨提示】你没有该模块权限或者模块不存在\");");
                                        }
                                    }

                                    //Debug
                                    //Sys_Module model = smb.GetInfoById(_keyid);
                                    //if (model == null)
                                    //{
                                    //    script.AppendLine("alert(\"【温馨提示】你没有该模块权限或者模块不存在 （MODULE_ID：" + _keyid + "）\");");
                                    //}
                                    //else
                                    //{
                                    //    script.AppendLine("top.Class_ItemCard_OprnNew.Run_ItemCard('" + _keyid + "','" + model.MODULE_NAME + "','" + "/" + model.MODULE_PATH + "?model_id=" + _keyid + "','0');");
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(Page, ex.Message);
                                }
                                break;
                            }
                    }
                }
                else
                {
                    script.AppendLine("alert(\"请正确传入参数\");");
                }

                #endregion 加载模块信息

                script.AppendLine("</script>");
                Response.Write(script.ToString());
                Response.End();
            }
        }

        #endregion 页面加载
    }
}